package emas.server.core;

import com.google.gwt.maps.client.geocode.Geocoder;
import com.google.gwt.maps.client.geocode.LatLngCallback;
import com.google.gwt.maps.client.geom.LatLng;

import emas.shared.Location;

public class GeoCoderManager {
	private Geocoder geocoder;
	
	private static GeoCoderManager instance = new GeoCoderManager();

	private LatLng addressLatlng = null;
	private String locationAddress=null;
	
	private GeoCoderManager(){
	}
	
	public void getLatLngfromAddressForLocation(Location location){
		geocoder.getLatLng(location.getAddress(),
				new LatLngCallback() {
			
					@Override
					public void onFailure() {

					}

					@Override
					public void onSuccess(LatLng point) {
						addressLatlng = LatLng.newInstance(point.getLatitude(),
								point.getLongitude());

					}
				});
		location.setLat(addressLatlng.getLatitude());
		location.setLng(addressLatlng.getLongitude());
		
	}
	
	public static GeoCoderManager getInstance() {
		if (instance == null) {
			instance = new GeoCoderManager();
		}

		return instance;
	}
	
}
